home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_unicodedata.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  8KB  |  215 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. ''' Test script for the unicodedata module.
  5.  
  6.     Written by Marc-Andre Lemburg (mal@lemburg.com).
  7.  
  8.     (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
  9.  
  10. '''
  11. import unittest
  12. import test.test_support as test
  13. import sha
  14. encoding = 'utf-8'
  15.  
  16. class UnicodeMethodsTest(unittest.TestCase):
  17.     expectedchecksum = 'a37276dc2c158bef6dfd908ad34525c97180fad9'
  18.     
  19.     def test_method_checksum(self):
  20.         h = sha.sha()
  21.         for i in range(65536):
  22.             char = unichr(i)
  23.             data = [
  24.                 u'01'[char.isalnum()],
  25.                 u'01'[char.isalpha()],
  26.                 u'01'[char.isdecimal()],
  27.                 u'01'[char.isdigit()],
  28.                 u'01'[char.islower()],
  29.                 u'01'[char.isnumeric()],
  30.                 u'01'[char.isspace()],
  31.                 u'01'[char.istitle()],
  32.                 u'01'[char.isupper()],
  33.                 u'01'[(char + u'abc').isalnum()],
  34.                 u'01'[(char + u'abc').isalpha()],
  35.                 u'01'[(char + u'123').isdecimal()],
  36.                 u'01'[(char + u'123').isdigit()],
  37.                 u'01'[(char + u'abc').islower()],
  38.                 u'01'[(char + u'123').isnumeric()],
  39.                 u'01'[(char + u' \t').isspace()],
  40.                 u'01'[(char + u'abc').istitle()],
  41.                 u'01'[(char + u'ABC').isupper()],
  42.                 char.lower(),
  43.                 char.upper(),
  44.                 char.title(),
  45.                 (char + u'abc').lower(),
  46.                 (char + u'ABC').upper(),
  47.                 (char + u'abc').title(),
  48.                 (char + u'ABC').title()]
  49.             h.update(u''.join(data).encode(encoding))
  50.         
  51.         result = h.hexdigest()
  52.         self.assertEqual(result, self.expectedchecksum)
  53.  
  54.  
  55.  
  56. class UnicodeDatabaseTest(unittest.TestCase):
  57.     
  58.     def setUp(self):
  59.         import unicodedata as unicodedata
  60.         self.db = unicodedata
  61.  
  62.     
  63.     def tearDown(self):
  64.         del self.db
  65.  
  66.  
  67.  
  68. class UnicodeFunctionsTest(UnicodeDatabaseTest):
  69.     expectedchecksum = 'cfe20a967a450ebc82ca68c3e4eed344164e11af'
  70.     
  71.     def test_function_checksum(self):
  72.         data = []
  73.         h = sha.sha()
  74.         for i in range(65536):
  75.             char = unichr(i)
  76.             data = [
  77.                 str(self.db.digit(char, -1)),
  78.                 str(self.db.numeric(char, -1)),
  79.                 str(self.db.decimal(char, -1)),
  80.                 self.db.category(char),
  81.                 self.db.bidirectional(char),
  82.                 self.db.decomposition(char),
  83.                 str(self.db.mirrored(char)),
  84.                 str(self.db.combining(char))]
  85.             h.update(''.join(data))
  86.         
  87.         result = h.hexdigest()
  88.         self.assertEqual(result, self.expectedchecksum)
  89.  
  90.     
  91.     def test_digit(self):
  92.         self.assertEqual(self.db.digit(u'A', None), None)
  93.         self.assertEqual(self.db.digit(u'9'), 9)
  94.         self.assertEqual(self.db.digit(u'\xe2\x85\x9b', None), None)
  95.         self.assertEqual(self.db.digit(u'\xe2\x91\xa8'), 9)
  96.         self.assertRaises(TypeError, self.db.digit)
  97.         self.assertRaises(TypeError, self.db.digit, u'xx')
  98.         self.assertRaises(ValueError, self.db.digit, u'x')
  99.  
  100.     
  101.     def test_numeric(self):
  102.         self.assertEqual(self.db.numeric(u'A', None), None)
  103.         self.assertEqual(self.db.numeric(u'9'), 9)
  104.         self.assertEqual(self.db.numeric(u'\xe2\x85\x9b'), 0.125)
  105.         self.assertEqual(self.db.numeric(u'\xe2\x91\xa8'), 9.0)
  106.         self.assertRaises(TypeError, self.db.numeric)
  107.         self.assertRaises(TypeError, self.db.numeric, u'xx')
  108.         self.assertRaises(ValueError, self.db.numeric, u'x')
  109.  
  110.     
  111.     def test_decimal(self):
  112.         self.assertEqual(self.db.decimal(u'A', None), None)
  113.         self.assertEqual(self.db.decimal(u'9'), 9)
  114.         self.assertEqual(self.db.decimal(u'\xe2\x85\x9b', None), None)
  115.         self.assertEqual(self.db.decimal(u'\xe2\x91\xa8', None), None)
  116.         self.assertRaises(TypeError, self.db.decimal)
  117.         self.assertRaises(TypeError, self.db.decimal, u'xx')
  118.         self.assertRaises(ValueError, self.db.decimal, u'x')
  119.  
  120.     
  121.     def test_category(self):
  122.         self.assertEqual(self.db.category(u'\xef\xbf\xbe'), 'Cn')
  123.         self.assertEqual(self.db.category(u'a'), 'Ll')
  124.         self.assertEqual(self.db.category(u'A'), 'Lu')
  125.         self.assertRaises(TypeError, self.db.category)
  126.         self.assertRaises(TypeError, self.db.category, u'xx')
  127.  
  128.     
  129.     def test_bidirectional(self):
  130.         self.assertEqual(self.db.bidirectional(u'\xef\xbf\xbe'), '')
  131.         self.assertEqual(self.db.bidirectional(u' '), 'WS')
  132.         self.assertEqual(self.db.bidirectional(u'A'), 'L')
  133.         self.assertRaises(TypeError, self.db.bidirectional)
  134.         self.assertRaises(TypeError, self.db.bidirectional, u'xx')
  135.  
  136.     
  137.     def test_decomposition(self):
  138.         self.assertEqual(self.db.decomposition(u'\xef\xbf\xbe'), '')
  139.         self.assertEqual(self.db.decomposition(u'\xc2\xbc'), '<fraction> 0031 2044 0034')
  140.         self.assertRaises(TypeError, self.db.decomposition)
  141.         self.assertRaises(TypeError, self.db.decomposition, u'xx')
  142.  
  143.     
  144.     def test_mirrored(self):
  145.         self.assertEqual(self.db.mirrored(u'\xef\xbf\xbe'), 0)
  146.         self.assertEqual(self.db.mirrored(u'a'), 0)
  147.         self.assertEqual(self.db.mirrored(u'\xe2\x88\x81'), 1)
  148.         self.assertRaises(TypeError, self.db.mirrored)
  149.         self.assertRaises(TypeError, self.db.mirrored, u'xx')
  150.  
  151.     
  152.     def test_combining(self):
  153.         self.assertEqual(self.db.combining(u'\xef\xbf\xbe'), 0)
  154.         self.assertEqual(self.db.combining(u'a'), 0)
  155.         self.assertEqual(self.db.combining(u'\xe2\x83\xa1'), 230)
  156.         self.assertRaises(TypeError, self.db.combining)
  157.         self.assertRaises(TypeError, self.db.combining, u'xx')
  158.  
  159.     
  160.     def test_normalize(self):
  161.         self.assertRaises(TypeError, self.db.normalize)
  162.         self.assertRaises(ValueError, self.db.normalize, 'unknown', u'xx')
  163.         self.assertEqual(self.db.normalize('NFKC', u''), u'')
  164.  
  165.     
  166.     def test_east_asian_width(self):
  167.         eaw = self.db.east_asian_width
  168.         self.assertRaises(TypeError, eaw, 'a')
  169.         self.assertRaises(TypeError, eaw, u'')
  170.         self.assertRaises(TypeError, eaw, u'ra')
  171.         self.assertEqual(eaw(u'\x1e'), 'N')
  172.         self.assertEqual(eaw(u' '), 'Na')
  173.         self.assertEqual(eaw(u'\xec\xa2\x94'), 'W')
  174.         self.assertEqual(eaw(u'\xef\xbd\xa6'), 'H')
  175.         self.assertEqual(eaw(u'\xef\xbc\x9f'), 'F')
  176.         self.assertEqual(eaw(u'\xe2\x80\x90'), 'A')
  177.  
  178.  
  179.  
  180. class UnicodeMiscTest(UnicodeDatabaseTest):
  181.     
  182.     def test_decimal_numeric_consistent(self):
  183.         count = 0
  184.         for i in xrange(65536):
  185.             c = unichr(i)
  186.             dec = self.db.decimal(c, -1)
  187.             if dec != -1:
  188.                 self.assertEqual(dec, self.db.numeric(c))
  189.                 count += 1
  190.                 continue
  191.         
  192.         self.assert_(count >= 10)
  193.  
  194.     
  195.     def test_digit_numeric_consistent(self):
  196.         count = 0
  197.         for i in xrange(65536):
  198.             c = unichr(i)
  199.             dec = self.db.digit(c, -1)
  200.             if dec != -1:
  201.                 self.assertEqual(dec, self.db.numeric(c))
  202.                 count += 1
  203.                 continue
  204.         
  205.         self.assert_(count >= 10)
  206.  
  207.  
  208.  
  209. def test_main():
  210.     test.test_support.run_unittest(UnicodeMiscTest, UnicodeMethodsTest, UnicodeFunctionsTest)
  211.  
  212. if __name__ == '__main__':
  213.     test_main()
  214.  
  215.